#! /usr/bin/env python
'''
Popen doesn't block, allowing you to interact with the process while it's running, or continue with other things in your Python program. The call to Popen returns a Popen object.
call does block. '''

import subprocess
# Put stderr and stdout into pipes
proc = subprocess.Popen("date",  shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)

#wait for process!
return_code = proc.wait()

# Read from pipes
for line in proc.stdout:
    print("stdout: " + line.rstrip())
for line in proc.stderr:
    print("stderr: " + line.rstrip())

